﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Vds2465Telegrams
{
	[TestClass]
	public class Telegram_Returning_CONFIRM_ACK_Test
	{
		[TestMethod]
		[Owner("Frank Eppink")]
		public void Test01_Equals_NoUserData()
		{
			// no user data
			Telegram_Returning_CONFIRM_ACK telegramReturningConfirmAck = new Telegram_Returning_CONFIRM_ACK(eDirection.ATE_to_RCT, 0x57, true, false, null);

			{
				// completely different type - NOT equal
				object dummyObject = new object();
				Assert.IsFalse(telegramReturningConfirmAck.Equals(dummyObject));
			}

			{
				// base class - NOT equal
				Telegram_Returning telegram2Compare = new Telegram_Returning(telegramReturningConfirmAck.Direction, telegramReturningConfirmAck.Address,
					eTelegramFunction_Returning.CONFIRM_ACK, telegramReturningConfirmAck.AccessDemandFlag, telegramReturningConfirmAck.DataFlowControlStopFlag);

				Assert.IsFalse(telegramReturningConfirmAck.Equals(telegram2Compare));
			}

			{
				// equal
				Telegram_Returning_CONFIRM_ACK telegramReturningConfirmAck2Compare = new Telegram_Returning_CONFIRM_ACK(telegramReturningConfirmAck.Direction, telegramReturningConfirmAck.Address,
					telegramReturningConfirmAck.AccessDemandFlag, telegramReturningConfirmAck.DataFlowControlStopFlag, null);

				Assert.IsTrue(telegramReturningConfirmAck.Equals(telegramReturningConfirmAck2Compare));
			}

			{
				// direction differs - NOT equal
				eDirection direction;
				if (telegramReturningConfirmAck.Direction == eDirection.ATE_to_RCT)
				{
					direction = eDirection.RCT_to_ACE;
				}
				else
				{
					direction = eDirection.ATE_to_RCT;
				}
				Telegram_Returning_CONFIRM_ACK telegramReturningConfirmAck2Compare = new Telegram_Returning_CONFIRM_ACK(direction, telegramReturningConfirmAck.Address,
					telegramReturningConfirmAck.AccessDemandFlag, telegramReturningConfirmAck.DataFlowControlStopFlag, null);
				Assert.IsFalse(telegramReturningConfirmAck.Equals(telegramReturningConfirmAck2Compare));
			}

			{
				// address differs - NOT equal
				Telegram_Returning_CONFIRM_ACK telegramReturningConfirmAck2Compare = new Telegram_Returning_CONFIRM_ACK(telegramReturningConfirmAck.Direction, (byte)(telegramReturningConfirmAck.Address - 1),
					telegramReturningConfirmAck.AccessDemandFlag, telegramReturningConfirmAck.DataFlowControlStopFlag, null);
				Assert.IsFalse(telegramReturningConfirmAck.Equals(telegramReturningConfirmAck2Compare));
			}

			{
				// AccessDemandFlag differs - NOT equal
				Telegram_Returning_CONFIRM_ACK telegramReturningConfirmAck2Compare = new Telegram_Returning_CONFIRM_ACK(telegramReturningConfirmAck.Direction, telegramReturningConfirmAck.Address,
					!telegramReturningConfirmAck.AccessDemandFlag, telegramReturningConfirmAck.DataFlowControlStopFlag, null);
				Assert.IsFalse(telegramReturningConfirmAck.Equals(telegramReturningConfirmAck2Compare));
			}

			{
				// DataFlowControlStopFlag differs - NOT equal
				Telegram_Returning_CONFIRM_ACK telegramReturningConfirmAck2Compare = new Telegram_Returning_CONFIRM_ACK(telegramReturningConfirmAck.Direction, telegramReturningConfirmAck.Address,
					telegramReturningConfirmAck.AccessDemandFlag, !telegramReturningConfirmAck.DataFlowControlStopFlag, null);
				Assert.IsFalse(telegramReturningConfirmAck.Equals(telegramReturningConfirmAck2Compare));
			}
		}
		
		[TestMethod]
		[Owner("Frank Eppink")]
		public void Test02_Equals_WithUserData()
		{
			// UserDataColl
			ReportType_Device reportType = new ReportType_Device(false, eReportSubType_Device.General);
			UserData userData = new UserData_02_StatusChangeReport2Confirm(0x01, 0x02, 0x03, eAddressExtension_1.Input, reportType);
			UserDataColl userDataColl = new UserDataColl();
			userDataColl.Add(userData);

			Telegram_Returning_CONFIRM_ACK telegramReturningConfirmAck = new Telegram_Returning_CONFIRM_ACK(eDirection.ATE_to_RCT, 0x57, true, false, userDataColl);

			{
				// equal properties but no user Data
				Telegram_Returning_CONFIRM_ACK telegramReturningConfirmAck2Compare = new Telegram_Returning_CONFIRM_ACK(telegramReturningConfirmAck.Direction, telegramReturningConfirmAck.Address,
					telegramReturningConfirmAck.AccessDemandFlag, telegramReturningConfirmAck.DataFlowControlStopFlag, null);

				Assert.IsFalse(telegramReturningConfirmAck.Equals(telegramReturningConfirmAck2Compare));
			}

			{
				// equal properties but different user Data
				ReportType_Technical reportType01 = new ReportType_Technical(false, eReportSubType_Technical.Emergency_3);
				UserData userData01 = new UserData_02_StatusChangeReport2Confirm(0x01, 0x02, 0x03, eAddressExtension_1.Input, reportType01);
				UserDataColl userDataColl2Compare = new UserDataColl();
				userDataColl2Compare.Add(userData01);

				Telegram_Returning_CONFIRM_ACK telegramReturningConfirmAck2Compare = new Telegram_Returning_CONFIRM_ACK(telegramReturningConfirmAck.Direction, telegramReturningConfirmAck.Address,
					telegramReturningConfirmAck.AccessDemandFlag, telegramReturningConfirmAck.DataFlowControlStopFlag, userDataColl2Compare);
				
				Assert.IsFalse(telegramReturningConfirmAck.Equals(telegramReturningConfirmAck2Compare));
			}

			{
				// equal properties equal user data
				Telegram_Returning_CONFIRM_ACK telegramReturningConfirmAck2Compare = new Telegram_Returning_CONFIRM_ACK(telegramReturningConfirmAck.Direction, telegramReturningConfirmAck.Address,
					telegramReturningConfirmAck.AccessDemandFlag, telegramReturningConfirmAck.DataFlowControlStopFlag, userDataColl);			

				Assert.IsTrue(telegramReturningConfirmAck.Equals(telegramReturningConfirmAck2Compare));
			}
		}

		[TestMethod]
		[Owner("Frank Eppink")]
		public void Test03_GetHashCode()
		{			
			{
				Telegram_Returning_CONFIRM_ACK telegramReturningConfirmAck = new Telegram_Returning_CONFIRM_ACK(eDirection.ATE_to_RCT, 0x07, false, true, null);
				int hashCode = telegramReturningConfirmAck.GetHashCode();
			}

			{
				ReportType_Technical reportType01 = new ReportType_Technical(false, eReportSubType_Technical.Emergency_3);
				UserData userData = new UserData_02_StatusChangeReport2Confirm(0x01, 0x02, 0x03, eAddressExtension_1.Input, reportType01);
				UserDataColl userDataColl = new UserDataColl();
				userDataColl.Add(userData);
				Telegram_Returning_CONFIRM_ACK telegramReturningConfirmAck = new Telegram_Returning_CONFIRM_ACK(eDirection.ATE_to_RCT, 0x07, false, true, userDataColl);
				int hashCode = telegramReturningConfirmAck.GetHashCode();
			}
		}

		[TestMethod]
		[Owner("Frank Eppink")]
		public void Test04_ToString()
		{			
			{
				Telegram_Returning_CONFIRM_ACK telegramReturningConfirmAck = new Telegram_Returning_CONFIRM_ACK(eDirection.RCT_to_ACE, 0xa7, false, true, null);
				string stringResult = telegramReturningConfirmAck.ToString();
				Assert.IsNotNull(stringResult);
			}

			{
				ReportType_Device reportType = new ReportType_Device(false, eReportSubType_Device.General);
				UserData userData = new UserData_02_StatusChangeReport2Confirm(0x01, 0x02, 0x03, eAddressExtension_1.Input, reportType);
				UserDataColl userDataColl = new UserDataColl();
				userDataColl.Add(userData);
				Telegram_Returning_CONFIRM_ACK telegramReturningConfirmAck = new Telegram_Returning_CONFIRM_ACK(eDirection.RCT_to_ACE, 0xa7, false, true, userDataColl);
				string stringResult = telegramReturningConfirmAck.ToString();
				Assert.IsNotNull(stringResult);
			}

			{
				ReportType_Device reportType = new ReportType_Device(false, eReportSubType_Device.General);
				UserData userData01 = new UserData_02_StatusChangeReport2Confirm(0x01, 0x02, 0x03, eAddressExtension_1.Input, reportType);
				UserDataColl userDataColl = new UserDataColl();
				userDataColl.Add(userData01);
				UserData_01_Priority userData02 = new UserData_01_Priority(0x56);
				userDataColl.Add(userData02);
				Telegram_Returning_CONFIRM_ACK telegramReturningConfirmAck = new Telegram_Returning_CONFIRM_ACK(eDirection.RCT_to_ACE, 0xa7, false, true, userDataColl);
				string stringResult = telegramReturningConfirmAck.ToString();
				Assert.IsNotNull(stringResult);
			}
		}
	}
}
